package lab_10.com.acme.bankapp.domain.bank;

public class CheckingAccount extends AbstractAccount  {
	
	// We don't need an extra entity for overdraft, as negative values of balance can be used
	// to denote overdraft. Not only this rids us of extra variable, it also simplifies logic,
	// which would have to process 2 entities in the other case.
	
	private double overdraft_limit;
	
	
	public CheckingAccount(double balance, double overdraft_limit) {
		super(balance);
		this.overdraft_limit = overdraft_limit;
	}
	
	@Override
	public void withdraw(double amount) {
		if (amount >=0 && maximumAmountToWithdraw() >= amount) {
			balance -= amount;
		}
		assert (balance >= -overdraft_limit):"Overdraft has exceeded overdraft limit";
	}

	@Override
	public double maximumAmountToWithdraw() {
		double value = balance + overdraft_limit;
		return (value >= 0)?value:0;
	}

	@Override
	public void printAllAccountData() {
		System.out.println("Checking account.");
		System.out.format("Balance: %1$f\n",balance);
		System.out.format("Overdraft limit: %1$f\n",overdraft_limit);
		System.out.format("Maximum ammount to withdraw: %1$f\n",maximumAmountToWithdraw());
		
	}
}
